package net.sx.minemodule.mvp.activities;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.util.Log;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.homegoods.area.model.SubModelList;
import com.homegoods.aroutercomment.ARouterPath;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.base.MyBaseFragmentActivity;
import com.kedll.library.util.ToastUtil;

import net.sx.minemodule.MineApiUtils;
import net.sx.minemodule.R;
import net.sx.minemodule.databinding.MineActivityIntegralBinding;
import net.sx.minemodule.mvp.bean.TestIntegralBean;
import net.sx.minemodule.mvp.item.TestIntegralItem;
import net.sx.minemodule.mvp.model.MineIntegralModel;
import net.sx.minemodule.mvp.presenters.MineIntegralPresenter;
import net.sx.minemodule.mvp.views.MineIntegralView;

import java.util.List;

import io.reactivex.functions.Consumer;

/**
 * 我的大洋
 *
 * @author 11470
 */
@Route(path = ARouterPath.PATH_MINE_INTEGRAL)
public class MineIntegralActivity extends MyBaseFragmentActivity<MineActivityIntegralBinding, MineIntegralPresenter> implements MineIntegralView {

    //    MultiTypeAdapter adapter = new MultiTypeAdapter();    //del shibo.zheng  19/06/13
    private String integralType = "";

    @Override
    protected int getLayout() {
        return R.layout.mine_activity_integral;
    }

    @Override
    protected void initEvent() {
        //购物车  测试
        MineApiUtils.getShoppingCart(1, 10,
                subModelList -> Log.d(TAG, "accept: =-==========="  + JSON.toJSONString(subModelList)),
                throwable -> Log.d(TAG, "accept: =-===========" + throwable.toString()));


        mPresenter.getIntegralData();
        mBinding.expiredIntegral.setOnClickListener(v -> {
            integralType = "expiredIntegral";   //过期积分
            ARouter.getInstance().build(ARouterPath.PATH_INTEGRAL_RECORD).withString("integralType", integralType).navigation();
        });
        mBinding.integralInfo.setOnClickListener(v -> {
            integralType = "integralInfo";   //积分明细
            ARouter.getInstance().build(ARouterPath.PATH_INTEGRAL_RECORD).withString("integralType", integralType).navigation();
        });
        mBinding.commentProblem.setOnClickListener(v -> ARouter.getInstance().build(ARouterPath.PATH_COMMON_PROBLEM).navigation());
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        setTitle("我的积分");

        //del shibo.zheng start 19/06/13
        /*mBinding.recyclerViewIntegral.setLayoutManager(new GridLayoutManager(this, 2,
                GridLayoutManager.VERTICAL, false));
        mBinding.recyclerViewIntegral.setAdapter(adapter);
        mPresenter.addTestData();*/
        //del shibo.zheng end 19/06/13
    }

    @Override
    protected void initToolBar(Bundle savedInstanceState) {
        super.initToolBar(savedInstanceState);
        setTopRightButton("历史积分记录", 0, v -> {
            integralType = "integralRecording"; //历史积分记录
            ARouter.getInstance().build(ARouterPath.PATH_INTEGRAL_RECORD).withString("integralType", integralType).navigation();
        });
    }

    @Override
    protected MineIntegralPresenter getPresenter() {
        return new MineIntegralPresenter(this);
    }

    @Override
    public void addData(List<TestIntegralBean> beanList) {
        //del shibo.zheng start  19/06/13
        /*for (TestIntegralBean bean : beanList) {
            TestIntegralItem item = bean.createItem(adapter);
            adapter.addItem(item);
        }*/
        //del shibo.zheng end  19/06/13
    }

    @Override
    public void addMineIntegralData(MineIntegralModel model) {
        mBinding.amount.setText(model.getPoint());              //设置我的积分
        mBinding.expirePoint.setText(model.getExpirePoint());   //设置过期积分
        mBinding.countPoint.setText(model.getCountPoint());     //设置总积分数量
    }
}
